package com.heima.comment.controller.v1;

import com.heima.comment.service.CommentService;
import com.heima.model.comment.dtos.CommentDTO;
import com.heima.model.comment.dtos.CommentLikeDTO;
import com.heima.model.comment.dtos.CommentSaveDTO;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {
    @Autowired
    CommentService commentService;
    /**
     * 保存评论
     * @return
     */
    @ApiOperation("保存评论")
    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody @Validated CommentSaveDTO dto) throws Exception {
        return commentService.saveComment(dto);
    }
    /**
     * 点赞评论
     * @param dto
     * @return
     */
    @ApiOperation("点赞评论")
    @PostMapping("/like")
    public ResponseResult like(@RequestBody @Validated CommentLikeDTO dto){
        return commentService.like(dto);
    }
    /**
     * 根据文章id查询评论列表
     * @return
     */
    @ApiOperation("根据文章id查询评论列表")
    @PostMapping("/load")
    public ResponseResult findByArticleId(@RequestBody @Validated CommentDTO dto){
        return commentService.findByArticleId(dto);
    }
}
